package com.yunhe.authority.controller.base;

import com.yunhe.authority.domain.base.Feedback;
import com.yunhe.authority.service.base.FeedbackService;
import com.yunhe.common.model.PageParam;
import com.yunhe.common.model.ResultObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

/**
 * @author zhengbo
 * @date 2021/5/20 15:47
 */

@Api(value = "feedback",description = "建议反馈", tags = {"Authority_Feedback"})
@RestController
@RequestMapping("/feedback")
public class FeedbackController {

    @Autowired
    private FeedbackService feedbackService;

    @ApiOperation("获取列表")
    @RequestMapping(value = "/searchList", method = RequestMethod.GET)
    public ResponseEntity<ResultObject> searchList(@ModelAttribute PageParam pageParam) {
        Iterable<Feedback> feedbackIterable = feedbackService.getList();
        return new ResponseEntity<>(new ResultObject<>(feedbackIterable), HttpStatus.OK);
    }

    @ApiOperation("发送建议反馈")
    @RequestMapping(value = "/sendFeedback", method = RequestMethod.POST)
    public ResponseEntity<ResultObject> sendFeedback(@RequestBody Feedback feedback) throws NoSuchAlgorithmException, InvalidKeyException, UnsupportedEncodingException {
        Feedback newFeedback = feedbackService.creatFeedback(feedback);
        return new ResponseEntity<>(new ResultObject<>(newFeedback), HttpStatus.OK);
    }

    @ApiOperation("小程序发送建议反馈")
    @RequestMapping(value = "/sendFeedbackForWeChat", method = RequestMethod.POST)
    public ResponseEntity<ResultObject> sendFeedbackForWeChat(@RequestBody Feedback feedback) throws NoSuchAlgorithmException, InvalidKeyException, UnsupportedEncodingException {
        Feedback newFeedback = feedbackService.sendFeedbackForWeChat(feedback);
        return new ResponseEntity<>(new ResultObject<>(newFeedback), HttpStatus.OK);
    }
}
